package cn.edu.xmu.datamining.tangzk.mralgos.secondarysort;

import org.apache.hadoop.io.RawComparator;
import org.apache.hadoop.io.WritableComparator;

/**
 * Grouping key sharing same the first part(id1).
 * 
 * @version 2013-8-2
 * @author tangzk
 * @Reviewer
 * 
 */
public class SecondarySortKeyGroupingComparator implements RawComparator<KeyPair> {

	private final static int INT_LEN = Integer.SIZE / 8;

	@Override
	public int compare(KeyPair o1, KeyPair o2) {
		return o1.getId1() - o2.getId1();
	}

	@Override
	public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {
		return WritableComparator
				.compareBytes(b1, s1, INT_LEN, b2, s2, INT_LEN);
	}

}
